package cn.zhou.servlet;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

@WebServlet("/servlet")
public class ServletDemo extends HttpServlet {
    public static final String ADD="add";
    public static final String DELETE="delete";
    @Override
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        request.setCharacterEncoding("utf-8");
        response.setContentType("text/html;charset=utf-8");
        String method = request.getParameter("method");
        if (ADD.equals(method)){
            request.getSession().setAttribute("msg","执行了add方法");
        }
        if(DELETE.equals(method)){
            request.getSession().setAttribute("msg","执行了delete方法");
        }

        System.out.println(request.getContextPath());
        response.sendRedirect("/hello.jsp");
    }

    @Override
    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        this.doPost(request, response);
    }
}
